package day20180129.designMode.one_Iterater;

/**
 * Created by 14394 on 2018/1/29.
 */
//书架迭代器的具体实现，即集合迭代器的具体实现
public class BookShelfIterator implements IteratorPattern {
    private BookShelf bookShelf;

    private int index;

    public BookShelfIterator(BookShelf bookShelf) {
        this.bookShelf = bookShelf;
        this.index = 0;
    }

    @Override
    public boolean hasNext() {
        if (index<bookShelf.getLength()){
            return true;
        }else {
            return false;
        }
    }

    @Override
    public Object next() {
        Book book = bookShelf.getBookAt(index);
        index++;
        return book;
    }
}
